//
//  SignInTableViewCell.m
//  OAProject
//
//  Created by yhj on 2017/2/24.
//  Copyright © 2017年 cdnunion. All rights reserved.
//

#import "SignInTableViewCell.h"


@interface SignInTableViewCell ()

@property(nonatomic,strong)UIView *bigView;

@property(nonatomic,strong)UIView *smallView;

@property(nonatomic,strong)UIView *lineView;

// 签到状态
@property(nonatomic,strong)UILabel *stateLabel;

// 时间
@property(nonatomic,strong)UILabel *timeLabel;

@property(nonatomic,strong)UIButton *stateBtn;

// wifi状态
@property(nonatomic,strong)UILabel *wiFiStateLabel;

@property(nonatomic,strong)UIImageView *stateImage;

@end

@implementation SignInTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        // ➡️Cell类型
        self.accessoryType=UITableViewCellAccessoryNone;

        self.bigView.hidden=NO;

        self.smallView.hidden=NO;

        self.lineView.hidden=NO;

        self.stateLabel.font=Font_Number(18);

        self.timeLabel.font=Font_Number(14);

        self.wiFiStateLabel.font=Font_Number(14);

        self.stateBtn.hidden=NO;

        self.stateImage.image=[UIImage imageNamed:@"noEnter"];

        self.backgroundColor=WhiteColor;

        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapEvent:)];
        [self addGestureRecognizer:tap];

    }
    return self;
}

-(void)tapEvent:(UITapGestureRecognizer *)sender
{
    if (_delegate&&[_delegate respondsToSelector:@selector(tapSignWithTag:)])
    {
        [_delegate tapSignWithTag:[NSString stringWithFormat:@"%ld",(long)sender.view.tag]];
    }
}


// lineView
-(UIView *)lineView
{
    if (!_lineView) {
        _lineView=[UIView new];
        _lineView.backgroundColor=[UIColor lightGrayColor];
        [self.contentView addSubview:_lineView];
        [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.mas_equalTo(0);
            make.width.mas_equalTo(1);
            make.left.mas_equalTo(kmargin*3.5);
        }];
    }
    return _lineView;
}

// bigView
-(UIView *)bigView
{
    if (!_bigView) {
        _bigView=[UIView new];
        ViewBorderRadius(_bigView,APPW/6,1,[UIColor lightGrayColor]);
        [self.contentView addSubview:_bigView];
        [_bigView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(kmargin);
            make.size.mas_equalTo(CGSizeMake(APPW/3,APPW/3));
            make.left.mas_equalTo(APPW/3);
        }];
    }
    return _bigView;
}


// smallVie
-(UIView *)smallView
{
    if (!_smallView) {
        _smallView=[UIView new];
        _smallView.backgroundColor=[UIColor lightGrayColor];
        ViewBorderRadius(_smallView,(APPW/3-kmargin)/2,1,ClearColor);
        [self.contentView addSubview:_smallView];
        [_smallView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.bigView.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(APPW/3-kmargin,APPW/3-kmargin));
            make.left.mas_equalTo((APPW-(APPW/3-kmargin))/2);
        }];
    }
    return _smallView;
}


// stateLabel
- (UILabel *)stateLabel
{
    if (!_stateLabel) {
        _stateLabel=[self getLabelWithText:@"上班签到" font:Font_Number(18) textColor:WhiteColor textAlignment:NSTextAlignmentCenter lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.contentView addSubview:_stateLabel];
        [_stateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.bigView.mas_centerY).offset(-kmargin*3/2);
            make.centerX.mas_equalTo(self.bigView.mas_centerX);
        }];
    }
    return _stateLabel;
}

// timeLabel
- (UILabel *)timeLabel
{
    if (!_timeLabel) {
        _timeLabel=[self getLabelWithText:@"12:23:34" font:Font_Number(14) textColor:WhiteColor textAlignment:NSTextAlignmentCenter lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.contentView addSubview:_timeLabel];
        [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.bigView.mas_centerY).offset(kmargin*3/2);
            make.centerX.mas_equalTo(self.bigView.mas_centerX);
        }];
    }
    return _timeLabel;
}

// wiFiStateLabel
- (UILabel *)wiFiStateLabel
{
    if (!_wiFiStateLabel) {
        _wiFiStateLabel=[self getLabelWithText:@"未进入Wi-Fi考勤范围" font:Font_Number(18) textColor:BlackColor textAlignment:NSTextAlignmentCenter lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.contentView addSubview:_wiFiStateLabel];
        [_wiFiStateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.bigView.mas_bottom).offset(kmargin);
            make.width.mas_equalTo(APPW/2);
            make.left.mas_equalTo(APPW/4);
        }];
    }
    return _wiFiStateLabel;
}

// stateImage
-(UIImageView *)stateImage
{
    if (!_stateImage) {
        _stateImage=[UIImageView new];
        [self.contentView addSubview:_stateImage];
        [_stateImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.wiFiStateLabel.mas_left).offset(kmargin);
            make.size.mas_equalTo(CGSizeMake(kmargin*2,kmargin*2));
            make.centerY.mas_equalTo(self.wiFiStateLabel.mas_centerY);
        }];
    }
    return _stateImage;
}

-(void)setIs_WiFi:(BOOL)is_WiFi
{
    _stateImage.image=[UIImage imageNamed:@"enter"];
    _wiFiStateLabel.text=@"已进入Wi-Fi考勤范围";
}

@end
